In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you would like to talk about tasks, solutions or technical problems, please visit our Discord servers. They are moderated by the community, but members of the support team are also active there.
Byteland had not always been a democratic country. There were also black pages in its book of history. One lovely day general Bytel - commander of the junta which had power over Byteland - decided to finish the long-lasting time of war and released imprisoned activists of the opposition. However, he had no intention to let the leader Bytesar free. He decided to chain him to the wall with the bytish chain. It consists of joined rings and the bar fixed to the wall. Although the rings are not joined with the bar, it is hard to take them off.
- 'General, why have you chained me to the prison walls and did not let rejoice at freedom!' cried Bytesar.
- 'But Bytesar, you are not chained at all, and I am certain you are able to take off the rings from the bar by yourself.' perfidiously answered general Bytel, and he added 'But deal with that before a clock strikes the cyber hour and do not make a noise at night, otherwise I will be forced to call Civil Cyber Police.'
Help Bytesar! Number the following rings of the chain with integers . We may put on and take off these rings according to the following rules:
In the first line of the standard input there is written one integer , . In the second line there are written integers (each of them is either 0 or 1) separated by single spaces. If , then the -th ring is put on the bar, and if , then the -th ring is taken off the bar.
The standard output should contain exactly one integer equal to the minimal number of moves necessary to take off all the rings of the bytish chain from the bar.
For the input data:
4 1 0 1 0
the correct result is:
6
Task author: Marcin Kubica.